﻿using UnityEngine;
using UnityEngine.UI;

namespace Code.CharacterSystem
{
    public class HealthBar:MonoBehaviour
    {
        [SerializeField]private Slider _slider;
        [SerializeField] private Image _fill;
        [SerializeField] private Gradient _gradient;

        public void SetMaxHealth(int health) 
        {
            _slider.maxValue = health;
            _slider.value = health;
            _fill.color = _gradient.Evaluate(1f);
        }

        public void SetHealth(int health) 
        {
            _slider.value = health;
            _fill.color = _gradient.Evaluate(_slider.normalizedValue);
        }
    }
}
